// pages/Qr-code-collection/Qr-code-collection.js
var request = require('../../utils/request.js')
var modal = require('../../utils/modal.js')
var config = require('../../config.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        countdownTime: 0,
        submit_id: {
            worksheet_id: ''
        },
        istTrue:false
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var id = options.orderId;
        var that = this;
        that.data.submit_id.worksheet_id = id;
        //实时刷新时间单位为毫秒
        var addTime = null;
        var ajaxTime = null;
        var countdownTime = 0;
        addTime = setInterval(function () {
            countdownTime += 1;
            that.setData({
                countdownTime: countdownTime
            });
        }, 1000);

        ajaxTime = setInterval(function () {
            if(that.data.istTrue){
                return false;
            }
            request.post({'path': config.paymentStatus}, that.data.submit_id).then(function (res) {
                console.log(res,'付款信息')
                console.log(that.data.submit_id,'id-------')
                if(that.data.istTrue){
                    return false;
                }
                if (res.data.ret == 0) {
                    var resData = res.data.data;
                    if (resData.pay_status == 3) {
                        that.setData({
                            istTrue : true
                        })
                        clearInterval(addTime);
                        clearInterval(ajaxTime);
                        wx.navigateTo({
                            url: '/pages/pay-success/pay-success' + '?orderId=' + id + '&&pay_status=' + resData.pay_status
                        })
                    } else if (resData.pay_status == 4) {
                        that.setData({
                            istTrue : true
                        })
                        clearInterval(addTime);
                        clearInterval(ajaxTime);
                        wx.navigateTo({
                            url: '/pages/pay-error/pay-error' + '?orderId=' + id + '&&pay_status' + resData.pay_status
                        })
                    } else {

                    }
                }
            },function(){
                if(that.data.istTrue){
                    return false;
                }
            })
        }, 5000)


    },
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
debugger
    },
})